<?php
class ome_event_trigger_shop_hqepay
{
    public $node_id = '1227722633';
    /**
     * 华强宝订阅
     *
     * @return void
     * @author 
     **/
    public function hqepay_pub($delivery_id)
    {
        
        // 检测是否开启华强宝物流
        if('false' == app::get('ome')->getConf('ome.delivery.hqepay')) return;

        // 检测是否已经绑定华强宝物流
        base_kvstore::instance('ome/bind/hqepay')->fetch('ome_bind_hqepay', $is_ome_bind_hqepay);
        
        if (!$is_ome_bind_hqepay) {
            $bind = kernel::single('erpapi_router_request')->set('hqepay',$this->node_id)->hqepay_bind();
            
            if ( $bind != true) {
                return ;
            }
            base_kvstore::instance('ome/bind/hqepay')->store('ome_bind_hqepay', true);
        }

        $deliveryModel = app::get('ome')->model('delivery');
        $delivery = $deliveryModel->getFinishDelivery($delivery_id);
        if (!$delivery) return;

        $corpModel = app::get('ome')->model('dly_corp');
        $corpList = $corpModel->getList('corp_id,type,name',array('corp_id'=>$delivery['logi_id']),0,1);

        $corp = array_shift($corpList);

        $sdf = array(
            'delivery_bn' => $delivery['delivery_bn'],
            'logi_no'     => $delivery['logi_no'],
            'logi_type'   => $corp['type'],
            'logi_name'   => $corp['name'],
        );

        kernel::single('erpapi_router_request')->set('hqepay',$this->node_id)->hqepay_pub($sdf,true);
    }
}

?>